package com.xian.service;

import com.xian.dao.RoleMapper;
import com.xian.pojo.Permission;
import com.xian.pojo.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class RoleServiceImpl implements RoleService{
    @Autowired
    private RoleMapper roleMapper;
    public List<Role> findAll() {
        return roleMapper.findAll();
    }

    public int save(Role role) {
        return roleMapper.save(role);
    }

    public Role findById(String id) {
        return roleMapper.findById(id);
    }

    public List<Permission> findNoP(String id) {
        return roleMapper.findNoP(id);
    }
    // 添加权限
    public void addPermission(String id, String[] pIds) {
        if (pIds != null && pIds.length != 0){
            for (String pId : pIds) {
                roleMapper.addPermission(id,pId);
            }
        }
    }
}
